package com.dlc.shop.platform.task;

import com.xxl.job.core.handler.annotation.XxlJob;
import com.dlc.shop.common.config.Constant;
import com.dlc.shop.common.util.RedisUtil;
import com.dlc.shop.service.FlowLogService;
import com.dlc.shop.service.FlowService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;


/**
 * @author yami
 */
@Component
@AllArgsConstructor
public class FlowAnalysisTask {


    private final FlowLogService flowLogService;
    private final FlowService flowService;


    /**
     * 根据设置的时间，将缓存中的记录插入到数据库
     */
    @XxlJob("insertFlowAnalysisLog")
    public void insertFlowAnalysisLog(){
        if (RedisUtil.hasKey(Constant.FLOW_ANALYSIS_LOG)){
            flowLogService.insertBatch();
        }
    }

    /**
     * 统计记录数据，储存到对应的数据表中
     */
    @XxlJob("statisticalFlowData")
    public void statisticalFlowData(){
        //更新数据再统计
        insertFlowAnalysisLog();
        flowService.statisticalData();
    }
}
